/**
 * @author yaoyuan
 * @version 1.0
 * @name zjzcVotingApp.Directive:keditorDirective
 * @description app 富文本编辑器指令集合
 */

'use strict';

// 定义app模块变量
angular.module('app.directive')
    .directive('kindEditor', ['$parse', 'uiService',function($parse, uiService) {

        return {
            restrict: 'EA',
            link: function(scope, element, attrs, ctrl) {
                var id = attrs.kindEditor;
                var mainElem = jQuery("#notice_send")[0];
                element.attr('id', id);
                var editor = KindEditor.create('#'+id, {
                    resizeType : 1,
                    filterMode: false,//是否开启过滤模式
                    urlType: 'domain',
                    height: '180',
                    filePostName: 'itemFile',
                    uploadJson :  server + '/uploadfile/gridfs', // 相对于当前页面的路径
                //    fileManagerJson :'/ems/kindeditor/jsp/file_manager_json.jsp',
                    allowFileManager : true,
                    items : [
                        'justifyleft', 'justifycenter', 'justifyright','justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'formatblock', 'fontsize', 'forecolor', 'hilitecolor', 'bold','italic', 'underline',
                        'image', 'hr', 'emoticons', 'baidumap', 'link', 'unlink', 'fullscreen'
                    ]
                });
                scope.$emit('editor:load', editor, attrs.test);

                mainElem && (function(aElem) {
                    var bodyElem = $("body"),
                        _Resize = function(argument) {
                            var mainH = aElem.offsetHeight;
                            if(bodyElem.hasClass('window1380')) {
                                editor.resize(null, mainH-340);
                            }else{
                                editor.resize(null, mainH-320);
                            }
                        }
                    $(window).resize(_Resize);
                    _Resize();
                })(mainElem);


             /**   scope.$on('$stateChangeStart', function(event) {
                    if(!editor.isEmpty() && !confirm('您确定要离开此页面？')) {
                        event.preventDefault();
                    }
                });**/

            }
        };
    }]);
